<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>奖品管理</title>
	<meta name="decorator" content="default"/>
	<%-- <script src="${ctxStatic }/sxdw/js/base.js" type="text/javascript"></script> --%>
	<script src="${ctxStatic }/sxdw/js/bak/join.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			var bigCat = "${award.bigCategory}";
			if("other" == bigCat)
			{
				$("#smallCategoryDiv").hide();
				$("#smallCategory").html("");
			}
			
			// 添加时，加载大小类
			var id = "${award.id}";
			if(!id)
			{
				var courseId = $("#courseId").val();
				if(courseId)
				{
					$("#courseId").change();
				}
			}
			
		});
		
		function createOptions(id,type,val)
		{
			if(null == id || "" == id)
			{
				return "";
			}
			return "<option value='" + id + "' " + "type='" + type + "'>" + val + "</option>";
		}
		
		// 根据课程二级联动大类
		function setBigCategory(obj,renderId)
		{
			var options = "<option value='' type='' selected='selected'>展示大类</option>";
			var val = obj.value;
			if("other" == val)
			{
				$("#"+renderId).hide();
				$("#" + renderId).html("");
				return;
			}
			else
			{
				$("#"+renderId).show();
			}
			var sign = $(obj).find("option:selected").attr("sign");
			var type = "course_type_" + sign;
			$.ajax({
			       type: "POST",
			       url: "${ctxFront}/ems/qryCategory",
			       dataType: "text",
			       data:"type="+type,
				   async: true,
			       success: function(jsonArea){
				       // 转换为json对象
				       jsonArea = eval('(' + jsonArea + ')');
				       
					   for(var area in jsonArea)
				   	   {
				   	  	 var value = jsonArea[area].value;
				   	  	 var type = jsonArea[area].type;
				   	  	 var name = jsonArea[area].name;
				   	  	 options += createOptions(value,type,name);
				   	   }
					   $("#" + renderId).html("");
				   	   $("#" + renderId).html(options);
				   	   $("#" + renderId).change();
			       }
			    });
		}
		
		// 根据type查询复合字典列表
		function setSubCategory(obj,renderId)
		{
			var options = "<option value='' selected='selected'>展示小类</option>";
			
			var sign = $("#courseId").find("option:selected").attr("sign");
			var val = obj.value;
			if("other" == val || "paint" == sign)
			{
				$("#" + renderId + "Div").hide();
				$("#" + renderId).html("");
				return;
			}
			else
			{
				$("#"+renderId + "Div").show();
			}
			var type = $(obj).find("option:selected").attr("type");
			var subType = type + "_" + val;
			$.ajax({
			       type: "POST",
			       url: "${ctxFront}/ems/qryCategory",
			       dataType: "text",
			       data:"type="+subType,
				   async: true,
			       success: function(jsonArea){
				       // 转换为json对象
				       jsonArea = eval('(' + jsonArea + ')');
				       
					   for(var area in jsonArea)
				   	   {
				   	  	 var value = jsonArea[area].value;
				   	  	 var type = jsonArea[area].type;
				   	  	 var name = jsonArea[area].name;
				   	  	 options += createOptions(value,type,name);
				   	   }
					   $("#" + renderId).html("");
				   	   $("#" + renderId).html(options);
				   	   $("#" + renderId).change();
			       }
			    });
		}

	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/ems/award/">奖品列表</a></li>
		<li class="active"><a href="${ctx}/ems/award/form?id=${award.id}">奖品<shiro:hasPermission name="ems:award:edit">${not empty award.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="ems:award:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="award" action="${ctx}/ems/award/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<%-- <div class="control-group">
			<label class="control-label">家长姓名：</label>
			<div class="controls">
				<form:input path="register" htmlEscape="false" maxlength="32" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">奖品来源：</label>
			<div class="controls">
				<%-- <form:input path="register" htmlEscape="false" maxlength="32" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span> --%>
				${'system' eq award.awardFrom?'系统报名':'现场报名'}
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">家长电话：</label>
			<div class="controls">
				<form:input path="mobile" htmlEscape="false" maxlength="32" class="input-xlarge"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">选手姓名：</label>
			<div class="controls">
				<%-- <form:input path="joiner" htmlEscape="false" maxlength="32" class="input-xlarge required"/> --%>
				<form:textarea path="joiner" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge required"/>
				<span class="help-inline"><font color="red">*</font> 多个选手姓名以英文逗号","隔开；每个人将生成一条奖品信息</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">展示类别：</label>
			<div class="controls">
				
				<form:select path="course.id" id="courseId" class="input-xlarge required" onchange="setBigCategory(this,'bigCategory')">
					<%-- <form:options items="${fns:getDictList('course_group_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/> --%>
					<c:forEach items="${courses }" var="course">
						<form:option value="${course.id }" sign="${course.sign }" label="${course.name }"/>
					</c:forEach>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">组别：</label>
			<div class="controls">
				<form:select path="groupType" class="input-xlarge required">
					<form:option value="" label="组别"/>
					<form:options items="${fns:getDictList('course_group_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">展示方式(个人/集体)：</label>
			<div class="controls">
				<form:select path="joinType" class="input-xlarge required">
					<form:option value="" label="展示方式"/>
					<form:options items="${fns:getDictList('course_join_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">展示大类：</label>
			<div class="controls">
				<form:select path="bigCategory" id="bigCategory" class="input-xlarge" onchange="setSubCategory(this,'smallCategory');">
					<form:option value="" label="展示大类"/>
					<%-- <form:options items="${fns:getDictList('course_join_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/> --%>
					<c:forEach items="${bigCategories}" var="big">
						<form:option value="${big.value }" type="${big.type }" label="${big.name }"/>
					</c:forEach>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group" id="smallCategoryDiv">
			<label class="control-label">展示小类：</label>
			<div class="controls">
				<form:select path="smallCategory" id="smallCategory" class="input-xlarge">
					<form:option value="" label="展示小类"/>
					<%-- <form:options items="${fns:getDictList('course_join_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/> --%>
					<c:forEach items="${smallCategories}" var = "small">
						<form:option value="${small.value }" label="${small.name }"/>
					</c:forEach>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">推选学校：</label>
			<div class="controls">
				<form:input path="school" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">获得荣誉：</label>
			<div class="controls">
				<form:input path="award" htmlEscape="false" maxlength="32" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">得分情况：</label>
			<div class="controls">
				<form:input path="score" htmlEscape="false" maxlength="32" class="input-xlarge"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">是否领取：</label>
			<div class="controls">
				<form:input path="status" htmlEscape="false" maxlength="2" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
				<form:select path="status" id="status" class="input-xlarge required">
					<form:option value="" label="是否领取"/>
					<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="ems:award:edit"><input id="btnSubmit" class="btn btn-primary" onclick="return saveAward('inputForm');" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>